package tt;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;

import org.apache.activemq.ActiveMQConnectionFactory;

public class ProducerTest {
	

	public static void main(String[] args) throws JMSException, InterruptedException {
		ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
		Connection con = factory.createConnection();
		con.start();
		Session sen = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
		Topic topic = sen.createTopic("aa");
		MessageProducer producer = sen.createProducer(topic);
		TextMessage msg = sen.createTextMessage("hehe");
		producer.send(msg);
		System.out.println("success");
		con.close();
	}
	/*public static void main(String[] args) throws JMSException, InterruptedException {
		// TODO Auto-generated method stub
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入发送消息的间隔");
		int interval = scanner.nextInt();
		ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
		Connection con = factory.createConnection();
		con.start();
		Session sen = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
		Queue queue = sen.createQueue("tt");
		MessageProducer producer = sen.createProducer(queue);
		TextMessage msg = sen.createTextMessage("hello word");
		for(int i=0;i<2000;i++) {
			Thread.sleep(interval);
			producer.send(msg);
		}
		con.stop();
		con.close();
		
	}
*/
}
